﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CeeSharpBlackJack
{
    class StandardHand : Hand
    {
        List<object> hand = new List<object>();
        private bool hasAce = false;
        public void addCard(object p)
        {
            hand.Add(p);
        }

        public string asObscuredString()
        {
            String cardsAsString = "? of ?"+Environment.NewLine;
            foreach (PlayingCard card in hand.Skip(1))
            {
                cardsAsString += card.getRank() + " of " + card.getSuit() + Environment.NewLine;
            }
            return cardsAsString;
        }

        public int getValue()
        {
            int cardValue = 0;
           
            foreach (PlayingCard card in hand)
            {
                switch (Enum.GetName(typeof(PlayingCard.Rank), card.getRank()))
                {
                    case "Two":
                        cardValue += 2;
                        break;
                    case "Three":
                        cardValue += 3;
                        break;
                    case "Four":
                        cardValue += 4;
                        break;
                    case "Five":
                        cardValue += 5;
                        break;
                    case "Six":
                        cardValue += 6;
                        break;
                    case "Seven":
                        cardValue += 7;
                        break;
                    case "Eight":
                        cardValue += 8;
                        break;
                    case "Nine":
                        cardValue += 9;
                        break;
                    case "Ace":
                        hasAce = true;
                        cardValue += 1;
                        break;
                    case "Ten":
                    case "Jack":
                    case "Queen":
                    case "King":
                        cardValue += 10;
                        break;
                }
            }

            if (hasAce)
            {
                if (cardValue + 10 < 21)
                {
                    cardValue += 10;
                }
                
            }
            return cardValue;
        }

        public string asString()
        {
            String cardsAsString = "";
            foreach (PlayingCard card in hand)
            {
                cardsAsString += card.getRank() + " of " + card.getSuit()+Environment.NewLine;
            }
            return cardsAsString.ToString();
        }
    }
}
